package yz.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.yarn.webapp.hamlet.Hamlet;

import java.net.URI;

public class demo4DownloadData {
    public static void main(String[] args) throws Exception{
        Configuration entries = new Configuration();
        FileSystem fileSystem = FileSystem.get(new URI("hdfs://master:9001"), entries,"root");

        //第一个路径，HDFS
        fileSystem.copyToLocalFile(new Path("/api/apiwolds.txt"),new Path("src/main/dataFile/apiwolds.txt"));

        /**
         * Exception in thread "main" java.io.FileNotFoundException: Destination exists and is not a directory: D:\data\Java_data\hadoop\hadoop\src\main\dataFile\apiwolds.txt
         * 	at org.apache.hadoop.fs.RawLocalFileSystem.mkdirsWithOptionalPermission(RawLocalFileSystem.java:529)
         * 	at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:504)
         * 	at org.apache.hadoop.fs.ChecksumFileSystem.mkdirs(ChecksumFileSystem.java:694)
         *
         * 	没有本地环境
         * 	1.找到对应hadoop的bin包
         * 	2.在win环境中配置对应的环境变量
         * 	3.重新打开idea来获取环境变量
         * 	4.执行winutils命令，有结果就执行成功
         */

        fileSystem.close();
    }
}
